
export const addZero =  function(val) {
    return val>9?val : '0' + val;
}

//毫秒数转换时间 ps: 2016/09/08 10:30
export const tmToFormatTime = function(time) {
    if (time) {
        let date = new Date(+time);
        let MM = addZero(date.getMonth() + 1);
        let dd = addZero(date.getDate());
        let hh = addZero(date.getHours());
        let mm = addZero(date.getMinutes());
        return `${date.getFullYear()}/${MM}/${dd}  ${hh}:${mm}`
    } else {
        return '';
    }
}

//毫秒数转换时间 ps: 2016.09.08 10:30:22
export const tmToFormatTimePoint = function(time) {
    if (time) {
        let date = new Date(+time);
        let MM = addZero(date.getMonth() + 1);
        let dd = addZero(date.getDate());
        let hh = addZero(date.getHours());
        let mm = addZero(date.getMinutes());
        let ss = addZero(date.getSeconds());
        return `${date.getFullYear()}.${MM}.${dd}  ${hh}:${mm}:${ss}`
    } else {
        return '';
    }
}

//优惠卷时间格式
export const couponTime = function(time) {
    if (time) {
        let date = new Date(+time);
        let MM = addZero(date.getMonth() + 1);
        let dd = addZero(date.getDate());
        // let hh = addZero(date.getHours());
        // let mm = addZero(date.getMinutes());
        // let ss = addZero(date.getSeconds());
        return `${date.getFullYear()}-${MM}-${dd}`
    } else {
        return '';
    }
}

//毫秒数转换时间 ps: 2016.09.08
export const tmToFormatTimeTow = function(time) {
     let date = time? new Date(+time) : new Date();
     let MM = addZero(date.getMonth() + 1);
     let dd = addZero(date.getDate());
     let hh = addZero(date.getHours());
     let mm = addZero(date.getMinutes());
     return `${date.getFullYear()}.${MM}.${dd}`
}

//价格格式化
export const formatPrice = function(price) {
    if (price > 0 || price ===0 ) return (+price).toFixed(2);
    return price;
}


//加载更多函数
export const loadMore = function(callback) {
    window.onscroll=  function() {
        let screenHeight = window.innerHeight;
        let scrollHeight = document.body.scrollTop;
        let height       = document.body.scrollHeight;
        callback(screenHeight, scrollHeight, height);
    }
}
//解绑滚动事件
export const unbindScroll = function() {
    window.onscroll= null;
}
